<?php



/*-----------------------------------------------------------------------------------



TABLE OF CONTENTS



- Exclude categories from displaying on the "Blog" page template.

- Exclude categories from displaying on the homepage.

- Register WP Menus

- Breadcrumb display

- Page navigation

- Post Meta

- Subscribe & Connect

- Comment Form Fields

- Comment Form Settings

- Archive Description

- WooPagination markup

- Google maps (for contact template)

- Twitter

- Shortcodes



-----------------------------------------------------------------------------------*/



/*-----------------------------------------------------------------------------------*/

/* Exclude categories from displaying on the "Blog" page template.

/*-----------------------------------------------------------------------------------*/









/*-----------------------------------------------------------------------------------*/

/* Page navigation */

/*-----------------------------------------------------------------------------------*/

if (!function_exists( 'woo_pagenav')) {

	function woo_pagenav() {


		global $woo_options;

        

		// If the user has set the option to use simple paging links, display those. By default, display the pagination.

		if ( array_key_exists( 'woo_pagination_type', $woo_options ) && $woo_options[ 'woo_pagination_type' ] == 'simple' ) {

			if ( get_next_posts_link() || get_previous_posts_link() ) {

		?>

            <nav class="nav-entries fix">

                <?php next_posts_link( '<span class="nav-prev fl">'. __( '<span class="meta-nav">&larr;</span> Older posts', 'woothemes' ) . '</span>' ); ?>

                <?php previous_posts_link( '<span class="nav-next fr">'. __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'woothemes' ) . '</span>' ); ?>

            </nav>

		<?php

			}

		} else {

			woo_pagination();



		} // End IF Statement



	} // End woo_pagenav()

} // End IF Statement







/*-----------------------------------------------------------------------------------*/

/* Register WP Menus 

/*-----------------------------------------------------------------------------------*/

if ( function_exists( 'wp_nav_menu') ) {

	add_theme_support( 'nav-menus' );

	register_nav_menus( array( 'primary-menu' => __( 'Primary Menu', 'woothemes' ) ) );
	register_nav_menus( array( 'top-menu' => __( 'Top menu', 'woothemes' ) ) );
	
    /*

    register_nav_menus( array( 'user-menu' => __( 'User Menu', 'woothemes' ) ) );

    */
}



/*-----------------------------------------------------------------------------------*/

/* Enable Home link in WP Menus

/*-----------------------------------------------------------------------------------*/


/*-----------------------------------------------------------------------------------*/

/* Google Maps */

/*-----------------------------------------------------------------------------------*/

function woo_maps_contact_output($args){



	$key = get_option('woo_maps_apikey');

	

	// No More API Key needed

	

	if ( !is_array($args) ) 

		parse_str( $args, $args );

		

	extract($args);	

	$mode = '';

	$streetview = 'off';	

	$map_height = get_option('woo_maps_single_height');

	$featured_w = get_option('woo_home_featured_w');

	$featured_h = get_option('woo_home_featured_h');

	$zoom = get_option('woo_maps_default_mapzoom');

	$type = get_option('woo_maps_default_maptype');

	$marker_title = get_option('woo_contact_title');

	if ( $zoom == '' ) { $zoom = 6; }   

	$lang = get_option('woo_maps_directions_locale');

	$locale = '';

	if(!empty($lang)){

		$locale = ',locale :"'.$lang.'"';

	}

	$extra_params = ',{travelMode:G_TRAVEL_MODE_WALKING,avoidHighways:true '.$locale.'}';

	if(empty($map_height)) { $map_height = 250;}

	

	if(is_home() && !empty($featured_h) && !empty($featured_w)){

	?>

    <div id="single_map_canvas" style="width:<?php echo $featured_w; ?>px; height: <?php echo $featured_h; ?>px"></div>

    <?php } else { ?> 

    <div id="single_map_canvas" style="width:100%; height: <?php echo $map_height; ?>px"></div>

    <?php } ?>

    <script src="<?php bloginfo('template_url'); ?>/includes/js/markers.js" type="text/javascript"></script>

    <script type="text/javascript"> 

		jQuery(document).ready(function(){

			function initialize() {

				

				

			<?php if($streetview == 'on'){ ?>



				

			<?php } else { ?>

				

			  	<?php switch ($type) {

			  			case 'G_NORMAL_MAP':

			  				$type = 'ROADMAP';

			  				break;

			  			case 'G_SATELLITE_MAP':

			  				$type = 'SATELLITE';

			  				break;

			  			case 'G_HYBRID_MAP':

			  				$type = 'HYBRID';

			  				break;

			  			case 'G_PHYSICAL_MAP':

			  				$type = 'TERRAIN';

			  				break;

			  			default:

			  				$type = 'ROADMAP';

			  				break;

			  	} ?>

			  	

			  	var myLatlng = new google.maps.LatLng(<?php echo $geocoords; ?>);

				var myOptions = {

				  zoom: <?php echo $zoom; ?>,

				  center: myLatlng,

				  mapTypeId: google.maps.MapTypeId.<?php echo $type; ?>

				};

			  	var map = new google.maps.Map(document.getElementById("single_map_canvas"),  myOptions);

				<?php if(get_option('woo_maps_scroll') == 'true'){ ?>

			  	map.scrollwheel = false;

			  	<?php } ?>

			  	

				<?php if($mode == 'directions'){ ?>

			  	directionsPanel = document.getElementById("featured-route");

 				directions = new GDirections(map, directionsPanel);

  				directions.load("from: <?php echo $from; ?> to: <?php echo $to; ?>" <?php if($walking == 'on'){ echo $extra_params;} ?>);

			  	<?php

			 	} else { ?>

			 

			  		var point = new google.maps.LatLng(<?php echo $geocoords; ?>);

	  				var root = "<?php bloginfo('template_url'); ?>";

	  				var callout =  '<?php echo str_replace("<br/><br/>","<br/>", preg_replace("/[\n\r]/","<br/>",get_option('woo_maps_callout_text'))); ?>';

	  				var the_link = '<?php echo get_permalink(get_the_id()); ?>';

	  				<?php $title = str_replace(array('&#8220;','&#8221;'),'"', $marker_title); ?>

	  				<?php $title = str_replace('&#8211;','-',$title); ?>

	  				<?php $title = str_replace('&#8217;',"`",$title); ?>

	  				<?php $title = str_replace('&#038;','&',$title); ?>

	  				var the_title = '<?php echo html_entity_decode($title) ?>'; 

	  				

	  			<?php		 	

			 	if(is_page()){ 

			 		$custom = get_option('woo_cat_custom_marker_pages');

					if(!empty($custom)){

						$color = $custom;

					}

					else {

						$color = get_option('woo_cat_colors_pages');

						if (empty($color)) {

							$color = 'red';

						}

					}			 	

			 	?>

			 		var color = '<?php echo $color; ?>';

			 		createMarker(map,point,root,the_link,the_title,color,callout);

			 	<?php } else { ?>

			 		var color = '<?php echo get_option('woo_cat_colors_pages'); ?>';

	  				createMarker(map,point,root,the_link,the_title,color,callout);

				<?php 

				}

					if(isset($_POST['woo_maps_directions_search'])){ ?>

					

					directionsPanel = document.getElementById("featured-route");

 					directions = new GDirections(map, directionsPanel);

  					directions.load("from: <?php echo htmlspecialchars($_POST['woo_maps_directions_search']); ?> to: <?php echo $address; ?>" <?php if($walking == 'on'){ echo $extra_params;} ?>);

  					

  					

  					

					directionsDisplay = new google.maps.DirectionsRenderer();

					directionsDisplay.setMap(map);

    				directionsDisplay.setPanel(document.getElementById("featured-route"));

					

					<?php if($walking == 'on'){ ?>

					var travelmodesetting = google.maps.DirectionsTravelMode.WALKING;

					<?php } else { ?>

					var travelmodesetting = google.maps.DirectionsTravelMode.DRIVING;

					<?php } ?>

					var start = '<?php echo htmlspecialchars($_POST['woo_maps_directions_search']); ?>';

					var end = '<?php echo $address; ?>';

					var request = {

       					origin:start, 

        				destination:end,

        				travelMode: travelmodesetting

    				};

    				directionsService.route(request, function(response, status) {

      					if (status == google.maps.DirectionsStatus.OK) {

        					directionsDisplay.setDirections(response);

      					}

      				});	

      				

  					<?php } ?>			

				<?php } ?>

			<?php } ?>

			



			  }

			  function handleNoFlash(errorCode) {

				  if (errorCode == FLASH_UNAVAILABLE) {

					alert("Error: Flash doesn't appear to be supported by your browser");

					return;

				  }

				 }



			

		

		initialize();

			

		});

	jQuery(window).load(function(){

			

		var newHeight = jQuery('#featured-content').height();

		newHeight = newHeight - 5;

		if(newHeight > 300){

			jQuery('#single_map_canvas').height(newHeight);

		}

		

	});



	</script>



<?php

}


/*-----------------------------------------------------------------------------------*/
/* Breadcrumb display */
/*-----------------------------------------------------------------------------------*/

add_action('woo_main_before','woo_display_breadcrumbs',10);
if (!function_exists( 'woo_display_breadcrumbs')) {
	function woo_display_breadcrumbs() {
		global $woo_options;
		if (!is_home()) {
			if ( isset( $woo_options['woo_breadcrumbs_show'] ) && $woo_options['woo_breadcrumbs_show'] == 'true' ) {
			echo '<section id="breadcrumbs">';
				woo_breadcrumbs();
			echo '</section><!--/#breadcrumbs -->';
			}
		}
	} // End woo_display_breadcrumbs()
} // End IF Statement

// Customise the breadcrumb
add_filter( 'woo_breadcrumbs_args', 'woo_custom_breadcrumbs_args', 10 );

if (!function_exists('woo_custom_breadcrumbs_args')) {
	function woo_custom_breadcrumbs_args ( $args ) {
		$textdomain = 'woothemes';
		$args = array('separator' => '&nbsp;&rsaquo;&nbsp;', 'before' => '', 'show_home' => __( 'Trang chủ', $textdomain ),);
		return $args;	
	} // End woo_custom_breadcrumbs_args()
}

/**
 * Form set againt value onsubmit
 */
 function _value($key){
    echo isset($_REQUEST[$key])?$_REQUEST[$key]:"";
 } 



/*-----------------------------------------------------------------------------------*/

/* END */

/*-----------------------------------------------------------------------------------*/

?>
